﻿#include "CBeltFactHy.h"
#include "CBeltSqlOper.h"
#include "UTearPointState.h"
#include "UVideoPanel.h"
#include "ULogInfoPane.h"
#include "CHeader.h"
#include "Belt.h"
CBeltFactHy::CBeltFactHy(QString sGuid,QString sName)
{
	m_sGuid = sGuid;
	m_sName = sName;
}

CBeltFactHy::~CBeltFactHy()
{
}

void CBeltFactHy::createAll(void * pData)
{
	Belt *pBelt = (Belt *)pData;
	pBelt->m_pBeltData = createBasicData();   //创建数据对象
	pBelt->m_pBeltWork = createWorkMngr();    //创建工作业务逻辑
	pBelt->m_pBeltCtrMgr = createBeltCtrMgr();//创建控制对象
	pBelt->m_pPointMgrBase = createMngrBase();
	pBelt->m_pBeltData->m_sId = pBelt->m_sId;
}

CBeltDataBase * CBeltFactHy::createBasicData()
{
	CBeltDataBase *pBeltData = new CBeltDataBase();
	pBeltData->m_sGuid = m_sGuid;
	pBeltData->m_sBeltName = m_sName;
	selectBeltData(pBeltData);
	m_pBeltData = pBeltData;
	return pBeltData;
}

QVector<QWidget*> CBeltFactHy::getPanelList()
{
	if (m_vecWidget.size() > 0)
	{
		return m_vecWidget;
	}
	for (int i = 0; i < enPanelCount; i++)
	{
		QWidget *pPanel = createPanel(i);
		pPanel->setProperty("id", i);
		m_vecWidget.push_back(pPanel);
	}
	return m_vecWidget;
}

CPointMgrBase * CBeltFactHy::createMngrBase()
{
	CPointMgrBase *pPointMgrBase = new CPointMgrBase(m_pBeltData);
	return pPointMgrBase;
}

QWidget * CBeltFactHy::getPanel(int nId)
{
	return createPanel(nId);
}

QWidget * CBeltFactHy::createPanel(int nId)
{
	UBasePanel *pPanel = nullptr;
	switch (nId)
	{
	case enVideoPanel:
		pPanel = new UVideoPanel();
		pPanel->setProperty("row", 2);
		pPanel->setProperty("col", 1);
		pPanel->setProperty("name", A2T("视频显示"));
		pPanel->initPanel(m_pBeltData,m_pBeltCtrMgr);
		break;
	case enStateInfoPanel:
		pPanel = new UTearPointState();
		pPanel->setProperty("row", 1);
		pPanel->setProperty("col", 1);
		pPanel->setProperty("name", A2T("皮带撕裂主要信息"));
		pPanel->initPanel(m_pBeltData, m_pBeltCtrMgr);
		break;
	case enLogInfoPanel:
		pPanel = new ULogInfoPane();
		pPanel->setProperty("row", 1);
		pPanel->setProperty("col", 2);
		pPanel->setProperty("name", A2T("皮带撕裂日志信息"));
		pPanel->initPanel(m_pBeltData, m_pBeltCtrMgr);
		break;
	default:
		break;
	}
	return pPanel;
}

CBeltWorkBase * CBeltFactHy::createWorkMngr()
{
	CBeltWorkBase *pBeltWork = new CBeltWorkBase(m_pBeltData);
	pBeltWork->threadStart();
	return pBeltWork;
}

CBeltCtrMgr * CBeltFactHy::createBeltCtrMgr()
{
	m_pBeltCtrMgr = new CBeltCtrMgr(m_pBeltData);
	return m_pBeltCtrMgr;
}
